package com.starsea.book.ui.newpage

import android.os.Bundle
import android.text.TextUtils
import androidx.activity.viewModels
import com.starsea.book.R
import com.starsea.book.base.VMBaseActivity
import com.starsea.book.constant.EventBus
import com.starsea.book.databinding.ActivityEditBinding
import com.starsea.book.ui.config.ConfigViewModel
import com.starsea.book.utils.postEvent
import com.starsea.book.utils.toastOnUi
import com.starsea.book.utils.viewbindingdelegate.viewBinding

/**
 * @author Lee
 * @createTime 2024-01-09 21 GMT+8
 * @desc : 文字编辑
 */
class EditActivity : VMBaseActivity<ActivityEditBinding, ConfigViewModel>() {

    override val binding by viewBinding(ActivityEditBinding::inflate)
    override val viewModel by viewModels<ConfigViewModel>()

    override fun onActivityCreated(savedInstanceState: Bundle?) {

        binding.rtvConfim.setOnClickListener {
            val content = binding.etContent.text.toString()

            if (TextUtils.isEmpty(content)) {
                toastOnUi("请输入昵称")
                return@setOnClickListener
            }

            postEvent(EventBus.EDIT_CONTENT, content)

            finish()
        }

        val content = intent.getStringExtra("content") ?: ""
        binding.etContent.setText(content)

        setTitle(R.string.title_nick_name)

    }

    override fun setTitle(resId: Int) {
        super.setTitle(resId)
        binding.titleBar.setTitle(resId)
    }


}